<?php if ( ! defined('SERVER_ROOT')) exit('No direct script access allowed');
/**
 * MVC Ultra - A ultralight weight MVC framework for PHP
 *
 * MVC ultra is very simple MVC framework that is designed to be easy to use and learn.
 * It does not have all of other frameworks but you add what you need when you need it
 * and understand better whats going on.
 *
 *@author Warren Thomas <wiley_warren@yahoo.com>
 *@copyright Copyright (c) 2012.
 *
 ** 20121027/Warren Thomas      - Created MVC Ultra
 *
 */

/**
 * ultra_controller is the base controller class for MVC Ultra
 *
 * ultra_controller has the default properties and methods necessary to
 * run MVC Ultra. It should to be extends to support mutilple controllers
 * for mvc architecture.
 *
 *@package core
 *
 */
class ultra_controller
{
    /**
     * This variable will hold the default 'view' portion of our MVC for this controller
     *
     * @access private
     * @property string $default_view
     * 
     */
    private $default_view = 'default';
    
    /**
     * This variable will hold the default action for this controller
     *
     * @access private
     * @property string $default_action
     * 
     */
    private $default_action = 'index';
    
    /**
     * This variable will hold the view object for this controller
     *
     * @access public
     * @static
     * @property ultra_view $view
     * 
     */
    public static $view = null;

    /**
     * This variable will holds general data for this controller
     *
     * @access private
     * @property array $data
     * 
     */
    private $data = array();
    
    /**
     * __construct() - base contructor method
     * 
     */
    public function __construct() {}
    
    /**
     * __set() - set data values being stored in controller
     *
     * @access public
     * @param string $name name of contoller property
     * @param mixed $value $value to be stored in named controller property
     * 
     * @return void
     */
    public function __set($name,$value) {
        if($name == 'default_view') $this->default_view = $value;
        if($name == 'default_action') $this->default_action = $value;
        if($name == 'view') self::$view = $value;
        $this->data[$name] = $value;
    }
    
    /**
     * __get() - get data values being stored in controller
     *
     * @access public
     * @param string $name name of contoller property
     * 
     * @return mixed
     */
    public function __get($name){
        if($name == 'default_view') return $this->default_view;
        if($name == 'default_action') return $this->default_action;
        if($name == 'view') return self::$view;
        if (array_key_exists($this->data,$name)) return $this->data[$name];
        throw new UnexpectedValueException("No value '$name' set in ".__CLASS__);
    }
}